<?php

namespace App\Entities\Auth;

use App\Libraries\Entities\BaseEntity;
use App\Libraries\Entities\MonitoringMode;

class Module extends BaseEntity
{
    protected $SortFlag = true;
    protected $StatusFlag = true;
    protected $CreatedFlag = MonitoringMode::All;
    protected $UpdatedFlag = MonitoringMode::All;
    protected $DescriptionFlag = true;
    protected $table = 'auth_modules';
    public $primaryKey = 'module_id';
    /**
     * @var array
     */
    protected $fillable = [
        'parent_id',
        'encode',
        'full_name',
        'icon',
        'url_address',
        'target',
        'is_menu',
        'expand_enable',
        'is_public',
        'params',
    ];

    /**
     * 拥有该权限的角色.
     *
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
     */
    public function roles()
    {
        return $this->morphToMany(Role::class, 'itemtable', 'auth_authorizes', 'itemtable_id', 'categorytable_id');
    }

    public function buttons()
    {
        return $this->hasMany(ModuleButton::class, 'module_id');
    }
}
